﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using RoadTeam.Standard;
using RoadTeam.Standard.FM;
using RoadTeam.BLL.FM;
using System.Web.Script.Serialization;

namespace RoadTeam.Pase.FM
{
    public class MeterDegreePase : BasePase
    {
        public static FmMeterDegree GetMeterDegree(string OrganIdentitifer, int PageSize, int CurrentPage, int AllCount)
        {
            FMMeterDegree bll = new FMMeterDegree();
            DataTable dt = bll.GetMeterDegree(OrganIdentitifer, PageSize, CurrentPage, AllCount);
            List<MeterDegree> li = DtToList<MeterDegree>(dt);
            FmMeterDegree meter = new FmMeterDegree();
            meter.Item = li.ToArray();
            return meter;
        }

        public static String GetMeterDegree(string OrganIdentitifer, int PageSize, int CurrentPage, int AllCount,bool flag)
        {
            FMMeterDegree bll = new FMMeterDegree();
            DataTable dt = bll.GetMeterDegree(OrganIdentitifer, PageSize, CurrentPage, AllCount);
            List<MeterDegree> li = DtToList<MeterDegree>(dt);
            FmMeterDegree meter = new FmMeterDegree();
            meter.Item = li.ToArray();
            meter.AllCount = bll.GetMeterDegreeCount(OrganIdentitifer);
               JavaScriptSerializer jscvt = new JavaScriptSerializer();
               return jscvt.Serialize(meter);
        }




        public static int GetMeterDegreeCount(String OrganIdentitifer)
        {
            FMMeterDegree bll = new FMMeterDegree();
            return bll.GetMeterDegreeCount(OrganIdentitifer);
        }

        public static bool UpdateMeterDegree(string Json)
        {
            JavaScriptSerializer jscvt = new JavaScriptSerializer();
            FmMeterDegree fmdegree = jscvt.Deserialize<FmMeterDegree>(Json);
            String StrDegreeID = String.Empty;
            foreach (MeterDegree item in fmdegree.Item)
            {
                StrDegreeID += item.DegreeID + ",";
            }
            StrDegreeID = StrDegreeID.Trim(',');
            if (!String.IsNullOrEmpty(StrDegreeID))
            {
            
                FMMeterDegree degreebll = new FMMeterDegree();
                DataTable dt = degreebll.GetMeterDegree(StrDegreeID);
                DataRow dr;
                DataRow[] drs;
                foreach (MeterDegree item in fmdegree.Item)
                {
                    drs = dt.Select(" DegreeID ="+item.DegreeID+" ");
                    if (drs.Count() == 0) continue;
                    dr = drs[0];
                    dr["PreDegree"] = item.PreDegree == "null" ? "0.00" : item.PreDegree;
                    dr["CurDegree"] = item.CurDegree == "null" ? "0.00" : item.CurDegree;
                    dr["Degree"] = item.Degree == "null" ? "0.00" : item.Degree;
                }
             return   degreebll.UpdateMeterDegree(dt);
            }
            return false;
        }
    }
}
